package com.xxxx.server;

import org.junit.Test;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: Honors
 * @create: 2021-09-17
 */
public class T5 {

    @Test
    public void t6() {

        BigDecimal num = new BigDecimal("31415926");
        System.out.println(num.intValue());
        System.out.println(num);
    }

    @Test
    public void t5() {
//        String tempAuthorStr = "张三;李四,拿破仑，王五；曹操";
//        String[] tmpAuthors = tempAuthorStr.split(";|,|；|，");
//        for (String au : tmpAuthors) {
//            System.out.println(au);
//        }
        String userName = "张三,李四,拿破仑_王五-曹操,,,,,," + "\r\n" + "66";
        String[] names = userName.split(";|,|；|，|-|_");
        for (String name : names) {
            System.out.println(name);
        }
        String same = "张三" + "\r\n" + "66";
        System.out.println(same);
    }

    /**
     * excel 日期数字处理
     *
     * @param days
     * @return
     */
    public static Date getDate(int days) {
        Calendar c = Calendar.getInstance();
        c.set(1900, 0, 1);
        c.add(Calendar.DATE, days - 2);
        return c.getTime();
    }

    @Test
    public void t4() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String time = "2022-2-28";
        Date d = null;
        try {
            d = sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cld = Calendar.getInstance();
        cld.setTime(d);
        System.out.println(cld.get(Calendar.YEAR));
        System.out.println(cld.get(Calendar.MONTH) + 1);
        System.out.println(cld.get(Calendar.DATE));

        Date d2 = cld.getTime();
        System.out.println(sdf.format(d) + "加一月：" + sdf.format(d2));
//        Date date = new Date();
//        System.out.println(date);

    }

    @Test
    public void t3() {
        Date date = new Date();
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//        calendar.add(Calendar.MONTH, 1);
//        System.out.println(calendar);

        int year = Integer.parseInt(String.format("%tY", date));
        int month = Integer.parseInt(String.format("%tm", date));
        int day = Integer.parseInt(String.format("%td", date));
        int hour = Integer.parseInt(String.format("%tH", date));
        int minute = Integer.parseInt(String.format("%tM", date));
        int second = Integer.parseInt(String.format("%tS", date));


        // 格式化开始日期
        String strMonth = "" + month;
        if (month < 10) {
            strMonth = "0" + month;
        }
        String strDay = "" + day;
        if (day < 10) {
            strDay = "0" + month;
        }
        // 开始日期
        String startTime = year + "-" + strMonth + "-" + strDay;

        // 格式化结束日期
        String entMonth = month + 1 + "";
        if (month >= 12) {
            year = year + 1;
            entMonth = "01";
        } else {
            month = month + 1;
            if (month < 10) {
                entMonth = "0" + month;
            }
        }
        // 结束日期
        String endTime = year + "-" + entMonth + "-" + strDay;

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        simpleDateFormat.format(date);
        Date startDate = null;
        Date endDate = null;
        try {
            startDate = simpleDateFormat.parse(startTime);
            endDate = simpleDateFormat.parse(endTime);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date d1 = startDate;
        Date d2 = endDate;
        System.out.println(d1);
        System.out.println(d2);

        System.out.println(startTime);
        System.out.println(endTime);

    }

    @Test
    public void t1() {
        List<Long> tpIds = new ArrayList<>();
        tpIds.add(18L);
        tpIds.add(12L);
        tpIds.add(13L);
        tpIds.add(18L);
        tpIds.add(25L);
        tpIds.add(11L);
        BigDecimal tpCostBudget = new BigDecimal("0");
        System.out.println(tpCostBudget);
        Long maxId = 0L;
        for (Long tpId : tpIds) {
            if (tpId.compareTo(maxId) > 0) {
                maxId = tpId;
            }
        }
        Long max = Collections.max(tpIds);
        System.out.println(max);
        System.out.println(maxId);
    }

    @Test
    public void t2() {

        List<String> titleList = new ArrayList<>();
        titleList.add("张三");
        titleList.add("李四");
        titleList.add("王五");
        titleList.add("赵六");
        String t2 = "";
        for (int i = 0; i < titleList.size(); i++) {
            String t1 = titleList.get(i);
            if (!t2.equals("")) {
                t2 = t2 + "," + t1;
            } else {
                t2 = t2 + t1;
            }
        }
        System.out.println(t2);
    }

}
